package com.neu.icloud.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neu.icloud.entity.Mechine;
import com.neu.icloud.mapper.MechineMapper;
import com.neu.icloud.service.MechineService;

@Service
public class MechineServiceImpl implements MechineService {

	@Autowired
	private MechineMapper mechineMapper;

	@Override
	public int addMechine(Mechine mechine) {
		return mechineMapper.addMechine(mechine);
	}

	@Override
	public int updateMechine(Mechine mechine) {
		return mechineMapper.updataMechine(mechine);
	}
	
	@Override
	public int updateMechineState(Mechine mechine) {
		return mechineMapper.updateMechineState(mechine);
	}

	@Override
	public int removeMechineByMechineId(String mechineId) {
		List<Mechine> listMechines = mechineMapper.listMechineByMechineId(mechineId);
		for (Mechine mechine : listMechines) {
			String a = mechine.getMechineState();
			if (a.equals("启用")) {
				return -1;
			}
		}
		return mechineMapper.removeMechineByMechineId(mechineId);
	}

	@Override
	public int removeMechineByFactoryId(Integer factoryId) {
		List<Mechine> listMechines = mechineMapper.listMechineByFactoryId(factoryId);
		for (Mechine mechine : listMechines) {
			String a = mechine.getMechineState();
			if (a.equals("启用")) {
				return -1;
			}
		}
		return mechineMapper.removeMechineByFactoryId(factoryId);
	}

	@Override
	public List<Mechine> listMechineByMechineId(String mechineId) {
		return mechineMapper.listMechineByMechineId(mechineId);
	}

	@Override
	public List<Mechine> listMechineByFactoryId(Integer factoryId) {
		return mechineMapper.listMechineByFactoryId(factoryId);
	}

	@Override
	public List<Mechine> selectAll() {
		return mechineMapper.selectAll();
	}

	@Override
	public int runNum(String mechineState) {
		// TODO Auto-generated method stub
		return mechineMapper.runNum(mechineState);
	}

	@Override
	public int allNum() {
		// TODO Auto-generated method stub
		return mechineMapper.allNum();
	}

}
